# coding = utf-8
# Author = Ann
# Start Date: 2023/6/27


import allure
from tools.selenium_widget import SeleniumWidget


class SeleniumBasicPackage(SeleniumWidget):
    # #############################################[BasicAttribute]#################################################
    def open(self, page_link):
        with allure.step("Open: '" + f"{page_link}" + "'"):
            self._open(page_link)

    def open_new_window_named_as(self, window_name):
        with allure.step("Open new window named as: '" + f"{window_name}" + "' for selenium"):
            self._open_new_window_named_as(window_name)

    def open_new_window(self, link):
        with allure.step("Open: '" + f"{link}" + "'"):
            self.open_new_window(link)

    def close_browser(self):
        with allure.step("Close Browser"):
            self._close_browser()

    def close_window_named_as(self, window_name):
        with allure.step("Close the window named as '" + f"{window_name}" + "'"):
            self._close_window_named_as(window_name)

    def refresh(self):
        with allure.step("Refresh the page"):
            self._refresh()

    def back(self):
        with allure.step("Page back"):
            self._back()

    def forward(self):
        with allure.step("Page forward"):
            self._forward()

    def switch_to_base_window_for_selenium(self):
        with allure.step("Switch to base window for selenium"):
            self._switch_to_base_window_for_selenium()

    def switch_to_new_window_for_selenium(self):
        with allure.step("Switch to new window for selenium"):
            self._switch_to_new_window_for_selenium()

    def switch_to_window_named_as_for_selenium(self, window_name):
        with allure.step("Switch to the window named as '" + f"{window_name}" + "' for selenium"):
            self._switch_to_window_named_as_for_selenium()

    def switch_to_window_where_url_is_for_selenium(self, url):
        with allure.step("Switch to the window where '" + f"{url}" + "' is for selenium"):
            self._switch_to_window_where_url_is_for_selenium(url)

    def switch_to_root_frame_for_selenium(self, ):
        with allure.step("Switch to the root frame for selenium"):
            self._switch_to_root_frame_for_selenium()

    def switch_to_frame_with_name_for_selenium(self, frame_name):
        with allure.step("Switch to the frame with name '" + f"{frame_name}" + "' frame for selenium"):
            self._switch_to_frame_with_name_for_selenium(frame_name)

    def switch_to_frame_for_selenium(self, element_locator):
        with allure.step("Switch to frame '" + f"{element_locator}" + "' for selenium"):
            self._switch_to_frame_for_selenium(element_locator)

    def just_wait_in(self, time_value):
        with allure.step("Just wait in " + f"{time_value}" + " seconds"):
            self._just_wait_in(time_value)

    def wait_for_window_to_close(self, window_title):
        with allure.step("Wait for window '" + f"{window_title}" + "' to close"):
            self._wait_for_window_to_close(window_title)

    def wait_new_window_popup_then_switch_to_new_window_for_selenium(self, time_value):
        with allure.step(
                "wait new window popup then switch to new window for selenium in '" + f"{time_value}" + "' seconds"):
            self._wait_new_window_popup_then_switch_to_new_window_for_selenium(time_value)

    def get_screenshot_for_selenium(self):
        with allure.step("Get screenshot for selenium"):
            self._get_screenshot_for_selenium()

    def get_screenshot_of_element_for_selenium(self, element_locator):
        with allure.step("Get screenshot of '" + f"{element_locator}" + "' for selenium"):
            self._get_screenshot_of_element_for_selenium(element_locator)

    def assert_that_window_title_is_for_selenium(self, title, time_value):
        with allure.step(
                "Assert that window title is '" + f"{title}" + "' for selenium which times out in " + f"{time_value} seconds"):
            self._assert_that_window_title_is_for_selenium(title, time_value)

    def assert_that_window_title_contains_for_selenium(self, content, time_value):
        with allure.step(
                "Assert that window title contains '" + f"{content}" + "' for selenium which times out in " + f"{time_value} seconds"):
            self._assert_that_window_title_contains_for_selenium(content, time_value)

    def assert_that_current_url_is_for_selenium(self, url, time_value):
        with allure.step(
                "Assert that current url is '" + f"{url}" + "' for selenium which times out in " + f"{time_value} seconds"):
            self._assert_that_current_url_is_for_selenium(url, time_value)

    def assert_that_current_url_contains_for_selenium(self, content, time_value):
        with allure.step(
                "Assert that current url contains '" + f"{content}" + "' for selenium which times out in " + f"{time_value} seconds"):
            self._assert_that_current_url_contains_for_selenium(content, time_value)

    def assert_that_current_url_matches_for_selenium(self, regex, time_value):
        with allure.step(
                "Assert that current url matches '" + f"{regex}" + "' for selenium which times out in " + f"{time_value} seconds"):
            self._assert_that_current_url_matches_for_selenium(regex, time_value)

    def click(self, element_locator):
        with allure.step("Click the '" + f"{element_locator}" + "'"):
            self._click(element_locator)

    def click_which_time_out_in(self, element_locator, time_value):
        with allure.step(
                "Click the '" + f"{element_locator}" + "' which time out in '" + f"{time_value}" + "' Seconds"):
            self._click_which_time_out_in(element_locator, time_value)

    def click_by_js_which_time_out_in(self, element_locator, time_value):
        with allure.step(
                "Click the '" + f"{element_locator}" + "' which time out in '" + f"{time_value}" + "' Seconds"):
            self._click_by_js_which_time_out_in(element_locator, time_value)

    def assert_element_is_visible_for_selenium(self, element_locator, time_until):
        with allure.step(
                "Assert '" + f"{element_locator}" + "' is visible which times out in " + f"{time_until} seconds"):
            self._assert_element_is_visible_for_selenium(element_locator, time_until)

    def assert_element_value_equals_expect_value_for_selenium(self, element_locator, expect_value):
        with allure.step("Assert '" + f"{element_locator}" + "' equals '" + f"{expect_value}" + "' for selenium"):
            self._assert_element_value_equals_expect_value_for_selenium(element_locator, expect_value)

    def assert_element_text_equals_expect_value_for_selenium(self, element_locator, expect_value):
        with allure.step("Assert '" + f"{element_locator}" + "' equals '" + f"{expect_value}" + "' for selenium"):
            self._assert_element_text_equals_expect_value_for_selenium(element_locator, expect_value)

    def initial_key_flag_default_for_selenium(self):
        with allure.step("Initial key flag default for selenium"):
            self._initial_key_flag_default_for_selenium()

    def check_key_flag_default_for_selenium(self):
        with allure.step("check key flag default for selenium"):
            self._check_key_flag_default_for_selenium()

    def assert_element_value_equals_expect_value_with_flag(self, element_locator, expect_value):
        with allure.step("Assert '" + f"{element_locator}" + "' equals '" + f"{expect_value}" + "' with flag"):
            self._assert_element_value_equals_expect_value_with_flag(element_locator, expect_value)

    def assert_element_text_equals_expect_value_with_flag(self, element_locator, expect_value):
        with allure.step("Assert '" + f"{element_locator}" + "' equals '" + f"{expect_value}" + "' with flag"):
            self._assert_element_text_equals_expect_value_with_flag(element_locator, expect_value)

    def search_elements_for_value_then_click_for_selenium(self, element_locator, value):
        with allure.step(
                "Search elements '" + f"{element_locator}" + "' for value '" + f"{value}" + "' then click for selenium"):
            self._search_elements_for_value_then_click_for_selenium(element_locator, value)

    def search_elements_for_text_then_click_for_selenium(self, element_locator, value):
        with allure.step(
                "Search elements '" + f"{element_locator}" + "' for text '" + f"{value}" + "' then click for selenium"):
            self._search_elements_for_text_then_click_for_selenium(element_locator, value)

    def search_elements_for_value_then_click_by_js_for_selenium(self, element_locator, value):
        with allure.step(
                "Search elements '" + f"{element_locator}" + "' for value '" + f"{value}" + "' then click by js for selenium"):
            self._search_elements_for_value_then_click_by_js_for_selenium(element_locator, value)

    def search_elements_for_text_then_click_by_js_for_selenium(self, element_locator, value):
        with allure.step(
                "Search elements '" + f"{element_locator}" + "' for text '" + f"{value}" + "' then click by js for selenium"):
            self._search_elements_for_text_then_click_by_js_for_selenium(element_locator, value)

    def double_click(self, element_locator):
        with allure.step("Double click '" + f"{element_locator}" + "'"):
            self._double_click(element_locator)

    def context_click(self, element_locator):
        with allure.step("Context click '" + f"{element_locator}" + "'"):
            self._context_click(element_locator)

    def wait_for_element_appear_for_selenium(self, element_locator, time_value):
        with allure.step("Waiting for '" + f"{element_locator}" + "' appear in page '" + "' for selenium"):
            self._wait_for_element_appear_for_selenium(element_locator, time_value)

    def scroll_element_into_view_for_selenium(self, element_locator):
        with allure.step("Scroll element '" + f"{element_locator}" + "' into view for selenium"):
            self._scroll_element_into_view_for_selenium(element_locator)

    def scroll_to_current_window_top_for_selenium(self):
        with allure.step("Scroll to current window top for selenium"):
            self._scroll_to_current_window_top_for_selenium()

    def scroll_to_current_window_bottom_for_selenium(self):
        with allure.step("Scroll to current window bottom for selenium"):
            self._scroll_to_current_window_bottom_for_selenium()

    def clear(self, element_locator):
        with allure.step("Clear the content of '" + f"{element_locator}" + "'"):
            self._clear(element_locator)

    def type_value_into_element_for_selenium(self, data_value, element_locator):
        with allure.step("Type '" + f"{data_value}" + "' into '" + f"{element_locator}" + "' for selenium"):
            self._type_value_into_element_for_selenium(data_value, element_locator)

    def type_value_into_element_by_js_for_selenium(self, data_value, element_locator):
        with allure.step("Type '" + f"{data_value}" + "' into '" + f"{element_locator}" + "' by js for selenium"):
            self._type_value_into_element_by_js_for_selenium(data_value, element_locator)

    def clear_and_type_value_into_element_for_selenium(self, data_value, element_locator):
        with allure.step("Clear and type '" + f"{data_value}" + "' into '" + f"{element_locator}" + "' for selenium"):
            self._clear_and_type_value_into_element_for_selenium(data_value, element_locator)

    def fetch_text_as_key_for_selenium(self, element_locator, set_key):
        with allure.step("Fetch text of '" + f"{element_locator}" + "' as key '" + f"{set_key}" + "' for selenium"):
            self._fetch_text_as_key_for_selenium(element_locator, set_key)

    def fetch_value_as_key_for_selenium(self, element_locator, set_key):
        with allure.step("Fetch value of '" + f"{element_locator}" + "' as key '" + f"{set_key}" + "' for selenium"):
            self._fetch_value_as_key_for_selenium(element_locator, set_key)

    def fetch_element_attribute_as_key_for_selenium(self, element_locator, attribute, set_key):
        with allure.step(
                "Fetch '" + f"{attribute}" + "' of '" + f"{element_locator}" + "' as key '" + f"{set_key}" + "' for selenium"):
            self._fetch_element_attribute_as_key_for_selenium(element_locator, attribute, set_key)

    def type_key_into_element_for_selenium(self, set_key, element_locator):
        with allure.step("Type key '" + f"{set_key}" + "' into '" + f"{element_locator}" + "' for selenium"):
            self._type_key_into_element_for_selenium(set_key, element_locator)

    def click_and_hold_for_selenium(self, element_locator):
        with allure.step("Click '" + f"{element_locator}" + "' and hold"):
            self._click_and_hold_for_selenium(element_locator)

    def type_username_for_role_into_element_for_selenium(self, role, element_locator):
        with allure.step("Type username for role '" + f"{role}" + "' into '" + f"{element_locator}" + "' for selenium"):
            self._type_username_for_role_into_element_for_selenium(role, element_locator)

    def type_password_for_role_into_element_for_selenium(self, role, element_locator):
        with allure.step("Type password for role '" + f"{role}" + "' into '" + f"{element_locator}" + "' for selenium"):
            self._type_password_for_role_into_element_for_selenium(role, element_locator)

    def type_password_for_key_into_element_for_selenium(self, cipher_text, aes_key, element_locator):
        with allure.step(
                "Type password '" + f"{cipher_text}" + "' for key '" + f"{aes_key}" + "' into '" + f"{element_locator}" + "' for selenium"):
            self._type_password_for_key_into_element_for_selenium(cipher_text, aes_key, element_locator)

    def drag_and_drop_for_selenium(self, source_element, target_element):
        with allure.step("drag '" + f"{source_element}" + "' and drop '" + f"{target_element}" + "' for selenium"):
            self._drag_and_drop_for_selenium(source_element, target_element)

    def drag_and_drop_by_offset_for_selenium(self, source_element, xoffset, yoffset):
        with allure.step("drag '" + f"{source_element}" + "' and drop '" + f"{xoffset},{yoffset}" + "' for selenium"):
            self._drag_and_drop_by_offset_for_selenium(source_element, xoffset, yoffset)

    def select_option_from_dropdownlist(self, option, dropdownlist):
        with allure.step("Select '" + f"{option}" + " form '" + f"{dropdownlist}"):
            self._select_option_from_dropdownlist(option, dropdownlist)

    def press_key_on(self, key_name, element_locator):
        with allure.step(f"Press '{key_name}' on '{element_locator}'"):
            self._press_key_on(key_name, element_locator)
